#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H

#include "Utils\Polygon_utils\ExtendedPolygon.h"
#include "Utils\UI_utils\Graphics.h"
#include "Utils\UI_utils\InputReader.h"

template <typename _K = Rational_kernel>
class Environment
{
public:
  typedef _K                                K;
  typedef std::vector<CGAL::Polygon_2<K> >  Polygon_vector;
  typedef Extended_polygon<K>               Extended_polygon;
  
  typedef Reference_point<K>                Reference_point;
  typedef std::vector<Reference_point>      Reference_point_vec;

private:
  Graphics              _graphics;
  
  Polygon_vector        _workspace;
  Extended_polygon      _robot;

  Reference_point       _source_configiration;
  Reference_point       _target_configiration;
public:
 
  Environment (int argc, char* argv[])
    :_graphics(argc,argv)
  {
    Input_reader reader;
    reader.read_configuration(argv[1], configuration); //read configuration file

    //init workspace
    std::string workspace_file_name = configuration.get_workspace_file_name();
    reader.read_polygons<K> (workspace_file_name,_workspace);
    
    //read robot
    std::string robot_file_name = configuration.get_robot_file_name();
    CGAL::Polygon_2<K> tmp_robot;
    reader.read_polygon<K>(robot_file_name, tmp_robot);
    _robot = Extended_polygon (tmp_robot);

    //read initial configuration for robot 
    std::string source_configuration_file_name = configuration.get_source_configuration_file_name();
    _source_configiration = reader.read_reference_point<K> (source_configuration_file_name);
    
    std::string target_configuration_file_name = configuration.get_target_configuration_file_name();
    _target_configiration = reader.read_reference_point<K> (target_configuration_file_name);
    
  }

  //draw functions
  void draw_workspace(QColor& color = QColor(0,0,255))
  {
    _graphics.draw_polygons<K>(_workspace, color);
  }
  void display()
  {
    _graphics.display();
  }
  //get functions
  Polygon_vector&       get_workspace() {return _workspace;}
  Extended_polygon&     get_robot()   {return _robot;}
  Reference_point&      get_source_configiration() {return _source_configiration;}
  Reference_point&		get_target_configiration() {return _target_configiration;}
}; //Environment

#endif //ENVIRONMENT_H